Sorting

data=RandomReal[{0,1},20]

dataS=Sort[data];

LineCoor[pos_,val_]:=Line[ {{pos,-val},{pos,val}}]

MakeLines[data_]:=Table[LineCoor[i,data[[i]]],{i,Length[data]}]

DrawLines[ data_, opts___]:=Graphics[MakeLines[data],opts,
			PlotRange-> {{1,Length[data]},{-1,1}},AspectRatio->0.4]

DrawLines[data, Axes->True, AxesOrigin->{0,0}]//Show

Show[DrawLines[dataS,Axes->True,AxesOrigin->{0,0}]]

MakePoints[data_] :=Table[Point[{i,data[[i]]}],{i,Length[data]}]

DrawPoints[data_,opts___]:=Graphics[MakePoints[data],opts,PlotRange-> {{1,Length[data]},{0,1}},
				Frame->True,FrameTicks->False,
		AspectRatio->1]

Show[DrawPoints[data,FrameTicks->True,Prolog->AbsolutePointSize[4]]]

Show[DrawPoints[dataS,FrameTicks->True,Prolog->AbsolutePointSize[4]]]

(* Clear["`*"] *)

data=RandomReal[{0,1},20]

dataS=Sort[data]

FunSort[data_List]:=data//.{x___,y_,z_,w___}/;y>z->{x,z,y,w}

FunSort[data]

BubbleSort[ data_List /; VectorQ[data,NumberQ]]:=
    Module[{result=data},
			Do[ Do[ 
			        If[ result[[j-1]]> result[[j]],
									t=result[[j-1]];      
					          result[[j-1]]=result[[j]];
						        result[[j]]=t], 
				        {j,2,i}], {i, Length[data], 1,-1}];
		   result]

dataS=BubbleSort[data]

Show[DrawLines[data]]

Show[DrawLines[dataS]]

Show[DrawPoints[data]]

Show[DrawPoints[dataS]]

data=RandomReal[{0,1},20]

BubbleSortVisual[data_List /; VectorQ[data,NumberQ],
	         fun_,num_:Infinity, graphopts___]:=
    Module[{result=data},
			Do[ Do[ 
			       If[ result[[j-1]]>result[[j]],
									t=result[[j-1]];      
					          result[[j-1]]=result[[j]];
						       result[[j]]=t], {j,2,i}];
			   If[ Mod[i,num]==0, Show[fun[result,graphopts]]],
				 {i, Length[data], 1,-1}];
		            Print[result];Show[fun[result,graphopts]]]

BubbleSortVisual[data, DrawLines,6,{AxesOrigin->{0,0}, Axes->True}]

BubbleSortVisual[data, DrawPoints,6,FrameTicks->True,Prolog->AbsolutePointSize[4]]

Sum[1,{i,N,1,-1},{j,i}]//Expand

First[Timing[BubbleSort[RandomReal[{0,1},50]]]]

First[Timing[BubbleSort[RandomReal[{0,1},100]]]]

First[Timing[BubbleSort[RandomReal[{0,1},200]]]]

First[Timing[Sort[RandomReal[{0,1},50]]]]

First[Timing[Sort[RandomReal[{0,1},100]]]]

First[Timing[Sort[RandomReal[{0,1},10000]]]]

First[Timing[Sort[RandomReal[{0,1},20000]]]]

First[Timing[Sort[RandomReal[{0,1},40000]]]]

Merge Sort

Quick Sort